package j2024.j202408;

import java.util.Scanner;

public class j0805 {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long x = in.nextLong();
        long[] fight = new long[n];
        for (int i = 0; i < n; i++) {
            fight[i] = in.nextLong();
        }
        for (int i = 0; i < n; i++) {
            if(x>=fight[i]){
                x+=fight[i];
            }else {
                x+=gcd(x,fight[i]);
            }
        }
        System.out.println(x);
    }
    public static long gcd(long a,long b){
        while(a%b!=0){
            long tmp = a%b;
            a = b;
            b = tmp;
        }
        return b;
    }


    public int maxValue (int[][] grid) {
        // write code here
        int n = grid.length,m =grid[0].length;
        int[][] dp = new int[n+1][m+1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                dp[i][j] += Math.max(dp[i-1][j],dp[i][j-1])+grid[i-1][j-1];
            }
        }
        return dp[n][m];
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        String[] s = new String[t];
        for (int i = 0; i < t; i++) {
            int n = in.nextInt();
            String[] ch = new String[n];
            for (int j = 0; j < n; j++) {
                ch[j] = in.next();
            }
            if(n==1){
                System.out.println("Yes");
            }else {
                if(n%2==0){
                    for (int j = 0; j < n; j++) {
                        int left = j;
                        int right = j+1;
                        while(left>=0 && right<n){
                            if(ch[left].equals(ch[right])==false){
                                System.out.println("No");
                                break;
                            }
                            left--;
                            right++;
                        }
                        if(left==0 && right==n-1&&ch[left].equals(ch[right])==true){
                            System.out.println("Yes");
                        }
                    }

                }else {
                    for (int j = 0; j < n; j++) {
                        int mid = j;
                        int left = mid-1,right = mid+1;
                        while (left>=0 && right<n){
                            if(ch[left].equals(ch[right])==false){
                                System.out.println("No");
                                break;
                            }
                            left--;
                            right++;
                        }
                        if(left==0 && right==n-1&&ch[left].equals(ch[right])==true){
                            System.out.println("Yes");
                        }
                    }
                }
            }
        }
    }
}
class leet1{
    /**
     * 1219. 黄金矿工
     */
    int[] dx = {0,0,-1,1};
    int[] dy = {1,-1,0,0};
    boolean[][] vis;
    int cou = 0;
    int n,m;
    public int getMaximumGold(int[][] grid) {
        n = grid.length;
        m = grid[0].length;
        vis = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(grid[i][j]!=0){
                    vis[i][j] = true;
                    dfs(grid,i,j,grid[i][j]);
                    vis[i][j] = false;
                }
            }
        }
        return cou;
    }
    public void dfs(int[][] grid,int i,int j,int path){
        cou = Math.max(path,cou);
        for (int k = 0; k < 4; k++) {
            int x = dx[k]+i;
            int y = dy[k]+j;
            if(x>=0 && x<n && y>=0 && y<m && grid[x][y]!=0 && !vis[x][y]){
                vis[x][y] = true;
                dfs(grid,x,y,path+grid[x][y]);
                vis[x][y] = false;
            }
        }
    }
}
class leet2{
    /**
     * 980. 不同路径 III
     */
    int[] dx = {0,0,-1,1};
    int[] dy = {1,-1,0,0};
    boolean[][] vis;
    int n,m;
    int count = 0;
    int ret = 0;
    public int uniquePathsIII(int[][] grid) {
        n = grid.length;
        m = grid[0].length;
        vis = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(grid[i][j]==0){
                    count++;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(grid[i][j]==1){
                    dfs(grid,i,j,0);
                }
            }
        }
        return ret;
    }
    public void dfs(int[][] g,int i,int j,int tmp){
        if(g[i][j]==2 && tmp==count){
            ret++;
            return;
        }
        if(g[i][j]==2 && tmp!=count){
            return;
        }
        for (int k = 0; k < 4; k++) {
            int x = i+dx[k];
            int y = j+dy[k];
            if(x>=0 && y>=0 && x<n && y<m && g[x][y]==2){
                dfs(g,x,y,tmp);
            }
            if(x>=0 && y>=0 && x<n && y<m && !vis[x][y] && g[x][y]==0){
                vis[x][y] = true;
                dfs(g,x,y,tmp+1);
                vis[x][y] = false;
            }
        }
    }
}
